<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表格</title>

<!-- 搭建HTTP服务，响应一个4行3列的表格，并要求表格有隔行换色效果，且点击单元格能高亮显示 -->
    
    <style>
        td {
            padding:20px 40px;
        }

        /* 设置奇数行颜色 */
        table tr:nth-child(odd){
            background: bisque;
        }

        /* 设置偶数行颜色 */
        table tr:nth-child(even){
            background: aquamarine;
        }

        table,td{
            border-collapse: collapse;
        }
    </style>
</head>
<body>
    <table border="1">
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
    </table>
    <script>
        //获取所有td
        let tds = document.querySelectorAll('td');
        //遍历
        tds.forEach(item=>{
            item.onclick = function(){
                this.style.background = '#222';
            }
        })
    </script>
</body>
</html>